package com.ltx.text.service.Impl;

import com.ltx.text.exception.CustomizeException;
import com.ltx.text.exception.Exception;
import com.ltx.text.model.Student;
import com.ltx.text.service.StudentService;

import java.util.HashMap;
import java.util.Map;

public class StudentServiceImpl implements StudentService {
    private static Map<Integer,Student> studentMap = new HashMap<>();
    @Override
    public Student add(Student student) {
        if (student.equals("") && student == null){
            throw new Exception(CustomizeException.STUDENT_NULL);
        }
        if (student.getId().toString().length() < 7){
            throw new Exception(CustomizeException.ID_SHORT);
        }
        if (student.getName().length() > 4 ){
            throw new Exception(CustomizeException.NAME_EMPTY);
        }
        if (student.getSubjects() == null){
            throw new Exception(CustomizeException.SUB_NULL);
        }
        studentMap.put(student.getId(), student);
        System.out.println(student);
        return student;
    }

    @Override
    public Student getById(Integer id) {
        Student student = studentMap.get(id);
        System.out.println(student);
        return student;
    }

    @Override
    public void delete(Integer id) {
        Student student = getById(id);
        Student remove = studentMap.remove(student);
        System.out.println("删除成功");
        return;
    }
}
